package com.jubaopen.dao.ibatis;

import java.util.List;
import java.util.Map;

import com.jubaopen.bean.Trade;
import com.jubaopen.dao.TradeDAO;

public class TradeDAOImpl extends BaseIBatisDao implements TradeDAO {

	@Override
	public int add(Trade trade) {
		return (Integer) this.getSqlMapClientTemplate().insert(
				"TradeMapper.insert", trade);
	}

	@Override
	public int update(Trade trade) {
		return this.getSqlMapClientTemplate().update("TradeMapper.update",
				trade);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Trade> getPagedList(Map<String, Object> entry) {
		return this.getSqlMapClientTemplate().queryForList(
				"TradeMapper.getPagedList", entry);
	}

	@Override
	public int getCount(Map<String, Object> entry) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getCount", entry);
	}

	public double getReceiveSum(Map<String, Object> map) {
		double sum = 0;
		Object ret = this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getReceiveSum", map);
		if (ret != null) {
			sum = (Double) ret;
		}
		return sum;
	}
	
	@Override
	public Trade getOneByOrderNo(String orderNo) {
		return (Trade) this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getByOrderNo", orderNo);
	}

	@Override
	public Trade getOneByPaymentNo(String paymentNo) {
		return (Trade) this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getByPaymentNo", paymentNo);
	}

	@Override
	public double getSettleSum(Map<String, Object> map) {
		double sum = 0;
		Object ret = this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getSettleSum", map);
		if (ret != null) {
			sum = (Double) ret;
		}
		return sum;
	}

	@Override
	public double getPaymentSum(Map<String, Object> map) {
		double sum = 0;
		Object ret = this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getPaymentSum", map);
		if (ret != null) {
			sum = (Double) ret;
		}
		return sum;
	}

	@Override
	public double getReceiptSum(Map<String, Object> map) {
		double sum = 0;
		Object ret = this.getSqlMapClientTemplate().queryForObject(
				"TradeMapper.getReceiptSum", map);
		if (ret != null) {
			sum = (Double) ret;
		}
		return sum;
	}

	@Override
	public List<Trade> getTradesByPayer(String str) {
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Trade> getTradesByPayee(int payeeId) {
		return this.getSqlMapClientTemplate().queryForList(
				"TradeMapper.getTradesByPayee", payeeId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Trade> getTradesByState(int state) {
		return this.getSqlMapClientTemplate().queryForList("TradeMapper.getTradesByState", state);
	}
	
	
}
